//
//  WmcSettingContentItemCell.swift
//  YPWatermarkCamera
//
//  Created by Json on 2023/7/21.
//

import UIKit

class WmcSettingContentItemCell: WmcSettingBaseItemCell {

    private(set) lazy var stackView: UIStackView = {
        let stackV = UIStackView()
        stackV.axis = .horizontal
        stackV.spacing = 8.0
        stackV.distribution = .fill
        stackV.alignment = .center
        return stackV
    }()

    private(set) lazy var contentLabel: UILabel = {
        let label = UILabel()
        label.font = 14.wmc_font
        label.textColor = UIColor.wmc_grayH8_8A8A99
        return label
    }()
    
    private(set) lazy var arrowView: UIImageView = {
        let imageView = UIImageView(image: "arrow_right".wmc_image)
        imageView.contentMode = .scaleAspectFit
        return imageView
    }()
    
    
    override func makeUI() {
        super.makeUI()
        // stackView
        addSubview(stackView)
        stackView.snp.makeConstraints { make in
            make.left.equalTo(Wmc_standardEdge.left)
            make.right.equalTo(-Wmc_standardEdge.right)
            make.top.bottom.equalToSuperview()
        }
        // 标题
        stackView.addArrangedSubview(titleLabel)
        // 内容
        stackView.addArrangedSubview(contentLabel)
        // 箭头
        stackView.addArrangedSubview(arrowView)
        arrowView.snp.makeConstraints { make in
            make.size.equalTo(12.0.wmc_autoHor)
        }
        // 设置约束优先级
        titleLabel.setContentHuggingPriority(.defaultLow, for: .horizontal)
        titleLabel.setContentCompressionResistancePriority(.defaultHigh, for: .horizontal)
        contentLabel.setContentHuggingPriority(.defaultHigh, for: .horizontal)
        contentLabel.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
    }
    
    override func didSetItem() {
        super.didSetItem()
        let contentItem = (item as? WmcSettingContentItem) ?? .init()
        contentLabel.text = contentItem.content
        contentLabel.isHidden = contentItem.content.isEmpty
    }

}
